define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'lottery/lotterydota2/index',
                    add_url: 'lottery/lotterydota2/add',
                    edit_url: 'lottery/lotterydota2/edit',
                    del_url: 'lottery/lotterydota2/del',
                    multi_url: 'lottery/lotterydota2/multi',
                    table: 'lottery_dota2',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'index',
                sortName: 'index',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'index', title: __('Index')},
                        {field: 'result', title: __('Result')},
                        {field: 'game', title: '游戏'},

                        {field: 'gamedota2.num_text', title: '单双开奖',operate:false},
                        {field: 'gamedota2.line_text', title: '阵营开奖',operate:false},
                        {field: 'gamedota2.type_text', title: '攻击方式开奖',operate:false},
                        {field: 'gamedota2.attr_text', title: '属性开奖',operate:false},

                        {field: 'result_at', title: __('Result_at'),operate:'RANGE',formatter: Table.api.formatter.datetime,addclass: 'datetimerange'},
                        {field: 'createtime', title: __('Createtime'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});